package com.andaily.domain.user;

import com.andaily.domain.AbstractDomain;
import com.andaily.domain.shared.PasswordHandler;

import java.util.Date;

/**
 * @author Shengzhao Li
 */
public class User extends AbstractDomain {

    /**
     * Unique, the user login name
     */
    protected String email;

    protected String password;
    /**
     * Option field
     */
    protected String city;
    protected String nickName;
    protected String cellPhone;
    /**
     * User setting
     */
    private UserSetting setting;

    protected Date lastLoginTime;

    /**
     * Use the field for identify the user if need verify.
     * For example: when register need active the user, will retrieve the user according to the field value
     */
    protected String verifyCode;

    public User() {
    }

    public User(String email, String password, String city) {
        this.email = email;
        this.password = password;
        this.city = city;
    }

    public Date lastLoginTime() {
        return lastLoginTime;
    }

    public String email() {
        return email;
    }

    public String username() {
        return email;
    }

    public String password() {
        return password;
    }

    public String city() {
        return city;
    }

    public String nickName() {
        return nickName;
    }

    public String cellPhone() {
        return cellPhone;
    }

    public String changeNewPassword() {
        String newPass = PasswordHandler.randomPassword();
        this.password = PasswordHandler.encryptPassword(newPass);
        return newPass;
    }

    public void update(String nickName, String cellPhone) {
        this.nickName = nickName;
        this.cellPhone = cellPhone;
    }

    public UserSetting setting() {
        return setting;
    }

    public String verifyCode() {
        return verifyCode;
    }

    public User verifyCode(String verifyCode) {
        this.verifyCode = verifyCode;
        return this;
    }

    public boolean isDeveloper() {
        return false;
    }
}
